package com.cn.yugan.Engine.Adapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cn.yugan.Engine.Holder.CollectionItemHolder;
import com.cn.yugan.Engine.Beans.ArticleListInfo;
import com.cn.yugan.mobile.R;

import java.util.ArrayList;

/**
 * Created by Rover on 2016/7/30 .
 * Email 357319517@qq.com
 */
public class CollectionListViewAdpater extends BaseAdapter {
    private Context context;
    private ArrayList<ArticleListInfo> mlist;
    private LayoutInflater layoutInflater;
    private CollectionItemHolder collectionItemHolder;

    public CollectionListViewAdpater(Context context, ArrayList<ArticleListInfo> mlist) {
        this.context = context;
        this.mlist = mlist;
        this.layoutInflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        collectionItemHolder = null;
        if (convertView == null) {
            collectionItemHolder = new CollectionItemHolder();
            convertView = layoutInflater.inflate(R.layout.list_item_collection, null);
            collectionItemHolder.aid = (TextView) convertView.findViewById(R.id.list_item_collection_aid);
            collectionItemHolder.title = (TextView) convertView.findViewById(R.id.list_item_collection_title);
            collectionItemHolder.time = (TextView) convertView.findViewById(R.id.list_item_collection_time);
            convertView.setTag(collectionItemHolder);
        } else {
            collectionItemHolder = (CollectionItemHolder) convertView.getTag();
        }
        String title = mlist.get(position).getTitle();
        collectionItemHolder.title.setText(Html.fromHtml(title));
        collectionItemHolder.time.setText(mlist.get(position).getTime());
        collectionItemHolder.aid.setText("yg"+mlist.get(position).getAid());
//        collectionItemHolder.commit.setText(String.valueOf(mlist.get(position).getComment()));
//        collectionItemHolder.author.setText("Up主:" + mlist.get(position).getAuthor());
//        collectionItemHolder.see.setText("围观:" + String.valueOf(mlist.get(position).getClick()));
//        LogUtils.d(position+"=====>"+mlist.get(position).getImg());
//        Picasso.with(context).load(context.getString(R.string.imgserverurl)+mlist.get(position).getImg()+"!cover120.90").error(R.mipmap.default_img).into(collectionItemHolder.img);
        return convertView;
    }

    public void refreshList(ArrayList<ArticleListInfo> mlist) {
        if (mlist == null) {

        } else {
            this.mlist = mlist;
        }

    }

    public void addList(ArrayList<ArticleListInfo> mlist) {
        if (mlist == null) {

        } else {
            this.mlist.addAll(mlist);
        }

    }
}
